POV-Ray : Newsgroups : povray.advanced-users : macros problems... : macros problems... Server Time
29 Jul 2024 12:28:26 EDT (-0400)
  macros problems...  
From:  Light Beam 
Date: 11 Mar 2002 15:14:40
Message: <3c8d1030@news.povray.org>
A few days ago I discover the joy to make my own programming in Pov-Ray...
The scene bellow is used to create a tiled flood, it works very well but
when I want to makes it a "#macro" the things goes bad the macro doesn't
seem to work !
Here is....

The scene that works :

//  Persistence of Vision Raytracer V3.1
//  World definition file.
//
//  Creating tiled floors with a macro...
// Z coordinate = up

background { color <0.500,0.600,0.800> }

camera {  //  Camera StdCam
  location  <      0.000,     -15.000,      8.000>
  sky       <    0.00000,     0.00000,     1.00000> // Use right
handed-system
  up        <        0.0,         0.0,         1.0> // Where Z is up
  right     <    1.35836,         0.0,         0.0> // Right Vector is
adjusted to compensate for spherical (Moray) vs. planar (POV-Ray) aspect
ratio
  angle         40.00000    // Vertical      30.000
  look_at   <      0.000,       0.000,       5.000>
}

//
// *******  L I G H T S *******
//

light_source {   // Light1
  <0.0, 0.0, 0.0>
  color rgb <1.000, 1.000, 1.000>
  translate  <0.0, -20.0, 20.0>
}


#declare caro =
union {
  box {<-1, -1, -1>, <1, 1, 1> scale <0.98, 1.0, 0.04> translate  0.04*z}
  box {<-1, -1, -1>, <1, 1, 1> scale <1.0, 0.98, 0.04> translate  0.04*z}
  box {<-1, -1, -1>, <1, 1, 1> scale <0.98, 0.98, 0.01> translate  0.09*z}
  sphere {<0,0,0>,1 scale 0.02 translate  <0.98, -0.98, 0.08>}
  sphere {<0,0,0>,1 scale 0.02 translate  <-0.98, -0.98, 0.08>}
  sphere {<0,0,0>,1 scale 0.02 translate  <0.98, 0.98, 0.08>}
  sphere {<0,0,0>,1 scale 0.02 translate  <-0.98, 0.98, 0.08>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 0.08> translate
 <0.98, -0.98, 0.0>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 0.08> translate
 <-0.98, -0.98, 0.0>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 0.08> translate  <-0.98,
0.98, 0.0>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 0.08> translate  <0.98,
0.98, 0.0>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 1.96> rotate -90.0*x
translate  <0.98, -0.98, 0.08>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 1.96> rotate -90.0*x
translate  <-0.98, -0.98, 0.08>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 1.96> rotate <-90.0,
0.0, -90.0> translate  <-0.98, -0.98, 0.08>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 1.96> rotate <-90.0,
0.0, -90.0> translate  <-0.98, 0.98, 0.08>}
  texture {/*pigment {color rgb <0.2, 0.2, .8>}*/ finish {reflection 0.2
phong_size 10 phong 0.2}}
  }

// number of tiles from left to right...
#declare X_max = 50;
// number of tiles front of the camera...
#declare Y_max = 60;
// randomize color and rotation (if rota = 1)
#declare Blue1 = seed(1);
#declare XY = seed(2);
#declare rota = 0;

// Preset colorsets...
#declare rnd_Red = pigment {color rgb <1- (rand(Blue1)/10), 0.2, 0.2>}
#declare rnd_Green = pigment {color rgb <0.2, 1- (rand(Blue1)/10), 0.2>}
#declare rnd_Blue = pigment {color rgb <0.2, 0.2, 1- (rand(Blue1)/10)>}
#declare rnd_Ivory = pigment {color rgb <0.9 - (rand(Blue1)/10), 0.9 -
(rand(Blue1)/10), 0.8 - (rand(Blue1)/10)>}

#macro TF(X_max, Y_max, )
// Create a tiled floor.
#declare carrelage = union {
#local StartY = 0;
#while (StartY <= Y_max - 1)
 #local StartX = 0;
 #while (StartX <= X_max - 1)
 object {caro
 // if rota enabled then randomly rotate the tiles
 // along X and Y
 #if (rota = 1)
 rotate <1-(rand(XY)*2), 1-(rand(XY)*2), 0>
 #end
 //
 translate <StartX*2.0, StartY*2.0, 0> pigment{rnd_Ivory}}
 #declare StartX = StartX + 1;
 #end
 #declare StartY = StartY + 1;
#end
}

// Place the 'carrelage' at the origin axis '(0, 0, 0)'
object {carrelage translate (x*(-1.0*(X_max-1)))}

// End of the carrelage utilisation...
// Place the rest of the scene here...

sphere {<-3.5,13,1.02>1 pigment{rgb .2} finish{reflection 0.4}}
sphere {<0,14,2.02>2 pigment{rgb .2} finish{reflection 0.5}}
sphere {<3.5,13,1.02>1 pigment{rgb .2} finish{reflection 0.4}}

fog {
  fog_type 1
  distance 350
  color rgb 1
}

And finaly the same scene with my 'trying-to-make-a-macro' macro that dont
work !!!

//  Persistence of Vision Raytracer V3.1
//  World definition file.
//
//  Creating tiled floors with a macro...
// Z coordinate = up

background { color <0.500,0.600,0.800> }

camera {  //  Camera StdCam
  location  <      0.000,     -15.000,      8.000>
  sky       <    0.00000,     0.00000,     1.00000> // Use right
handed-system
  up        <        0.0,         0.0,         1.0> // Where Z is up
  right     <    1.35836,         0.0,         0.0> // Right Vector is
adjusted to compensate for spherical (Moray) vs. planar (POV-Ray) aspect
ratio
  angle         40.00000    // Vertical      30.000
  look_at   <      0.000,       0.000,       5.000>
}

//
// *******  L I G H T S *******
//

light_source {   // Light1
  <0.0, 0.0, 0.0>
  color rgb <1.000, 1.000, 1.000>
  translate  <0.0, -20.0, 20.0>
}


#declare caro =
union {
  box {<-1, -1, -1>, <1, 1, 1> scale <0.98, 1.0, 0.04> translate  0.04*z}
  box {<-1, -1, -1>, <1, 1, 1> scale <1.0, 0.98, 0.04> translate  0.04*z}
  box {<-1, -1, -1>, <1, 1, 1> scale <0.98, 0.98, 0.01> translate  0.09*z}
  sphere {<0,0,0>,1 scale 0.02 translate  <0.98, -0.98, 0.08>}
  sphere {<0,0,0>,1 scale 0.02 translate  <-0.98, -0.98, 0.08>}
  sphere {<0,0,0>,1 scale 0.02 translate  <0.98, 0.98, 0.08>}
  sphere {<0,0,0>,1 scale 0.02 translate  <-0.98, 0.98, 0.08>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 0.08> translate
 <0.98, -0.98, 0.0>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 0.08> translate
 <-0.98, -0.98, 0.0>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 0.08> translate  <-0.98,
0.98, 0.0>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 0.08> translate  <0.98,
0.98, 0.0>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 1.96> rotate -90.0*x
translate  <0.98, -0.98, 0.08>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 1.96> rotate -90.0*x
translate  <-0.98, -0.98, 0.08>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 1.96> rotate <-90.0,
0.0, -90.0> translate  <-0.98, -0.98, 0.08>}
  cylinder {<0,0,1>, <0,0,0>, 1 scale <0.02, 0.02, 1.96> rotate <-90.0,
0.0, -90.0> translate  <-0.98, 0.98, 0.08>}
  texture {/*pigment {color rgb <0.2, 0.2, .8>}*/ finish {reflection 0.2
phong_size 10 phong 0.2}}
  }

// number of tiles from left to right...
//#declare X_max = 50;
// number of tiles front of the camera...
//#declare Y_max = 60;
// randomize color and rotation (if rota = 1)
#declare Blue1 = seed(1);
#declare XY = seed(2);
//#declare rota = 0;

// Preset colorsets...
#declare rnd_Red = pigment {color rgb <1- (rand(Blue1)/10), 0.2, 0.2>}
#declare rnd_Green = pigment {color rgb <0.2, 1- (rand(Blue1)/10), 0.2>}
#declare rnd_Blue = pigment {color rgb <0.2, 0.2, 1- (rand(Blue1)/10)>}
#declare rnd_Ivory = pigment {color rgb <0.9 - (rand(Blue1)/10), 0.9 -
(rand(Blue1)/10), 0.8 - (rand(Blue1)/10)>}

// Create a tiled floor.
#macro TF(X_maxx, Y_maxx, rota, pig)
#declare X_max = X_maxx;
#declare Y_max = Y_maxx;
#declare carrelage = union {
#local StartY = 0;
#while (StartY <= Y_max - 1)
 #local StartX = 0;
 #while (StartX <= X_max - 1)
 object {caro
 // if rota enabled then randomly rotate the tiles
 // along X and Y
 #declare rotaa = rota;
 #if (rota = 1)
 rotate <1-(rand(XY)*2), 1-(rand(XY)*2), 0>
 #end
 //
 translate <StartX*2.0, StartY*2.0, 0> pigment{pig}}
 #declare StartX = StartX + 1;
 #end
 #declare StartY = StartY + 1;
#end
}
#end

// Place the 'carrelage' at the origin axis '(0, 0, 0)'
//object {carrelage translate (x*(-1.0*(X_max-1)))}

TF (50,60, 1, rnd_Ivory)

// End of the carrelage utilisation...
// Place the rest of the scene here...

sphere {<-3.5,13,1.02>1 pigment{rgb .2} finish{reflection 0.4}}
sphere {<0,14,2.02>2 pigment{rgb .2} finish{reflection 0.5}}
sphere {<3.5,13,1.02>1 pigment{rgb .2} finish{reflection 0.4}}

fog {
  fog_type 1
  distance 350
  color rgb 1
}

I dont really understand whats going on !


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.